/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;
 
import dto.LoaiTau;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import util.ConnectToMySql;

public class LoaiTauDAO {
     public static List<LoaiTau> LayDSLoaiTau() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException{
         List<LoaiTau> listLoaiTau = new ArrayList<LoaiTau>();

        Connection conn = ConnectToMySql.getConnection();
        if (conn != null) {
            try {
                CallableStatement cs = conn.prepareCall("select * from LoaiTau");
                 ResultSet rs = cs.executeQuery();
                if (rs != null) {
                    while (rs.next()) {
                        LoaiTau s = new LoaiTau();
                        s.setMaloaitau(rs.getInt("maloaitau"));
                        s.setTenloaitau(rs.getString("tenloaitau")); 
                        listLoaiTau.add(s);
                    }
                }
            } catch (Exception ex) {
                System.out.println(ex);
                return null;
            }
        }

        return listLoaiTau;
    }
    
    public static LoaiTau LayThongTinLoaiTau(int maLoaiTau)throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException{
        LoaiTau loai = new  LoaiTau();

        Connection conn = ConnectToMySql.getConnection();
        if (conn != null) {
            try {
                CallableStatement cs = conn.prepareCall("select * from LoaiTau where maloaitau=?");
                cs.setInt(1, maLoaiTau);
                 ResultSet rs = cs.executeQuery();
                if (rs != null) {
                    while (rs.next()) {
                        LoaiTau s = new LoaiTau();
                        s.setMaloaitau(rs.getInt("maloaitau"));
                        s.setTenloaitau(rs.getString("tenloaitau")); 
                        loai= s;
                    }
                }
            } catch (Exception ex) {
                System.out.println(ex);
                return null;
            }
        }

        return loai;
    }
}
